#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define eb emplace_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)

using namespace std;

using ll = long long;
using pii = pair < int, int >;
using veg = vector < pii >;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 3e5 + 10;

int a[N], n, cnt;
ll ans;
int mx;

void solve() {
	veg pot;
	rep(i, 2, n) if(a[i] >= a[i - 1]) pot.eb(a[i - 1], a[i]);
	sort(pot.begin(), pot.end(), [&](auto a, auto b) { return a.fi ^ b.fi ? a.fi < b.fi : a.se > b.se; });
	int rig = -1e9;
	for(auto v : pot) mx = max(mx, min(rig, v.se) - v.fi), rig = max(rig, v.se);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	n = in; rep(i, 1, n) a[i] = in, (i > 1 && (ans += abs(a[i] - a[i - 1])));
	solve(); reverse(a + 1, a + n + 1); solve(); mx *= 2;
	rep(i, 2, n - 1) {
		mx = max(mx, abs(a[i] - a[i + 1]) - abs(a[1] - a[i + 1]));
		mx = max(mx, abs(a[i] - a[i - 1]) - abs(a[n] - a[i - 1]));
	}
	printf("%lld\n", ans - mx);
	return 0;
}
